/**
 * Created with IntelliJ IDEA.
 * Description:验证回文串
 * User: wangxin
 * Date: 2024-09-16
 * Time: 10:55
 */
public class test1 {
    public static boolean isValidChar(char ch){
        if(ch >= 'a'&&ch <= 'z'||ch >= '0'&&ch <= '9'){
            return true;
        }
        return false;
    }
    public static boolean isPalindrome(String s) {
        String str1 = s.toLowerCase();
        int left = 0;
        int right = str1.length() - 1;
        while(left < right){
            while (left < right&&!isValidChar(str1.charAt(left))){
                left++;
            }
            while (left < right&&!isValidChar(str1.charAt(right))){
                right--;
            }
            if(str1.charAt(left) != str1.charAt(right)){
                return false;
            }
            else{
                left++;
                right--;
            }
        }

       return true;

    }

    public static void main(String[] args) {
        String s = "race a car";
        boolean ret  = isPalindrome(s);
        System.out.println(ret);
    }
}
